package java8.chapter08.test;

public class StrategyMain {

	private static class IsAllowerCase implements ValidationStrategy {

		@Override
		public boolean execute(String s) {
			return s.matches("[a-z]+");
		}

	}

	private static class IsNumeric implements ValidationStrategy {

		@Override
		public boolean execute(String s) {
			return s.matches("\\d+");
		}

	}

	interface ValidationStrategy {
		
		public boolean execute(String s);
		
	}

	private static class Validator {
		
		private final ValidationStrategy strategy;

		public Validator(ValidationStrategy v) {
			this.strategy = v;
		}
		
		public boolean validate(String s) {
			return strategy.execute(s);
		}
		
	}

	public static void main(String[] args) {
		Validator v1 = new Validator(new IsNumeric());
		System.out.println(v1.validate("aaaa"));
		Validator v2 = new Validator(new IsAllowerCase());
		System.out.println(v2.validate("bbbb"));
		
		Validator v3 = new Validator((String s) -> s.matches("\\d+"));
		System.out.println(v3.validate("aaaa"));
		Validator v4 = new Validator((String s) -> s.matches("[a-z]+"));
		System.out.println(v4.validate("bbbb"));
	}

}